import { computed } from "vue";

// 计算属性，返回包装后一个可传参的计算属性函数
export function useComputed(fn) {
  const fnMap = new Map();
  return function (...args) {
    const key = JSON.stringify(args);
    if (fnMap.get(key)) {
      return fnMap.get(key);
    }

    const result = computed(() => {
      return fn(...args);
    });
    fnMap.set(key, result);
    return result;
  };
}
